/*
 * @Author: qiang
 * @Date: 2021-12-26 17:09:13
 * @LastEditTime: 2021-12-27 21:39:20
 * @LastEditors: qiang
 * @Description:
 */
import { history } from 'umi';
import autoRoute from '@/utils/auto';
import Cookie from 'js-cookie';
import routeConfig from '@/routes/routeConfig';
import './global.css';

const t = true;

export function render(oldRender: () => void) {
  const isLogin = Cookie.get('token');
  fetch('/').then((auth) => {
    if (isLogin) {
      // 判断权限
      oldRender();
    } else {
      history.push('/login');
      oldRender();
    }
  });
}

interface PatchRoutesprops {
  routes: any[];
}

export function patchRoutes({ routes }: PatchRoutesprops) {
  autoRoute(routeConfig).forEach((item: { path: any; component: any }) => {
    routes[1].routes.unshift({
      path: item.path,
      exact: true,
      component: item.component,
    });
  });
}
